home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / boot / sunprom / devSunProm.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-17  |  4.5 KB  |  179 lines

  1. /* 
  2.  * devSunProm.c --
  3.  *
  4.  *    Routines that access the Sun PROM device drivers.  This code is
  5.  *    based on SunOS bootstrap code in boot/os/devio.c
  6.  *
  7.  * Copyright 1989 Regents of the University of California
  8.  * Permission to use, copy, modify, and distribute this
  9.  * software and its documentation for any purpose and without
  10.  * fee is hereby granted, provided that the above copyright
  11.  * notice appear in all copies.  The University of California
  12.  * makes no representations about the suitability of this
  13.  * software for any purpose.  It is provided "as is" without
  14.  * express or implied warranty.
  15.  */
  16.  
  17. #ifdef notdef
  18. static char rcsid[] = "$Header: /sprite/src/boot/sunprom/RCS/devSunProm.c,v 1.2 90/09/17 11:05:25 jhh Exp Locker: rab $ SPRITE (Berkeley)";
  19. #endif /* not lint */
  20.  
  21.  
  22. #include "sprite.h"
  23. #include "stdlib.h"
  24. #include "user/fs.h"
  25. #include "dev.h"
  26. #include "devFsOpTable.h"
  27. #include "boot.h"
  28. #include "machMon.h"
  29. #include "fs.h"
  30. #include "vm.h"
  31.  
  32. #define DEV_BSIZE DEV_BYTES_PER_SECTOR
  33.  
  34. #define READ 1
  35. #define WRITE 2
  36.  
  37. /*
  38.  * Our stand-alone I/O request block.
  39.  */
  40. MachMonIORequest *saioPtr;
  41.  
  42.  
  43. /*
  44.  *----------------------------------------------------------------------
  45.  *
  46.  * SunPromDevOpen --
  47.  *
  48.  *    Open the device used for booting.  This depends on the initialization
  49.  *    of the devicePtr->data field done in Dev_Config.
  50.  *
  51.  * Results:
  52.  *    SUCCESS or FAILURE.
  53.  *
  54.  * Side effects:
  55.  *    None.
  56.  *
  57.  *----------------------------------------------------------------------
  58.  */
  59. ReturnStatus
  60. SunPromDevOpen(devicePtr)
  61.     Fs_Device    *devicePtr;    /* Sprite device description */
  62. {
  63.     MachMonBootParam *paramPtr = (MachMonBootParam *)devicePtr->data;
  64.     MachMonDevInfo *devInfoPtr;
  65.     char *buffer;
  66.  
  67.     devInfoPtr = paramPtr->bootDevice->b_devinfo;
  68.     /*
  69.      * Setup the I/O request block;
  70.      */
  71.     saioPtr = (MachMonIORequest *)malloc(sizeof(MachMonIORequest));
  72.     saioPtr->si_flgs = 0;
  73.     saioPtr->si_boottab = paramPtr->bootDevice;
  74.     saioPtr->si_devdata = (char *)0;
  75.     saioPtr->si_ctlr = paramPtr->ctlrNum;
  76.     saioPtr->si_unit = paramPtr->unitNum;
  77.     saioPtr->si_boff = paramPtr->partNum;
  78.     saioPtr->si_cyloff = 0;
  79.     saioPtr->si_offset = 0;
  80.     saioPtr->si_bn = 0;
  81.     saioPtr->si_ma = (char *)0;
  82.     saioPtr->si_cc = 0;
  83.     saioPtr->si_sif = (struct saif *)0;
  84.     saioPtr->si_devaddr = (char *)0;
  85.     saioPtr->si_dmaaddr = (char *)0;
  86.  
  87.     if (devInfoPtr) {
  88.     /*
  89.      * The dev info describes how to map the device in, how much
  90.      * DMA space to set up, and how much local memory the device needs.
  91.      * Assume that the PROM device is already all set up.
  92.      */
  93. #ifdef notdef
  94.     Mach_MonPrintf("devInfoPtr: dma %d lcl %d max %d\n",
  95.         devInfoPtr->d_dmabytes, devInfoPtr->d_localbytes,
  96.         devInfoPtr->d_maxiobytes);
  97. #endif
  98.     if (devInfoPtr->d_dmabytes > 0) {
  99.         /*
  100.          * Allocate space for DMA, then map it into the DMA region of VM.
  101.          */
  102.         buffer = malloc(devInfoPtr->d_dmabytes);
  103.         buffer = VmMach_DMAAlloc(devInfoPtr->d_dmabytes, buffer);
  104.         saioPtr->si_dmaaddr = buffer;
  105.     }
  106.     if (devInfoPtr->d_localbytes > 0) {
  107.         saioPtr->si_devdata = malloc(devInfoPtr->d_localbytes);
  108.     }
  109.     }
  110.     if ( (paramPtr->bootDevice->b_open)(saioPtr) == 0) {
  111.     return(SUCCESS);
  112.     } else {
  113.     return(FAILURE);
  114.     }
  115. }
  116.  
  117.  
  118. /*
  119.  *----------------------------------------------------------------------
  120.  *
  121.  * SunPromDevRead --
  122.  *
  123.  *    Read from the boot device used for booting.
  124.  *
  125.  * Results:
  126.  *    SUCCESS or FAILURE.
  127.  *
  128.  * Side effects:
  129.  *    The read operation.
  130.  *
  131.  *----------------------------------------------------------------------
  132.  */
  133. ReturnStatus
  134. SunPromDevRead(devicePtr, ioPtr, replyPtr)
  135.     Fs_Device    *devicePtr;    /* Sprite device description */
  136.     Fs_IOParam  *ioPtr;
  137.     Fs_IOReply  *replyPtr;
  138. {
  139.     register int numBytes;
  140.     register int totalBytes;
  141.     register int maxlen;
  142.     register int len;
  143.  
  144.     saioPtr->si_bn = ioPtr->offset / DEV_BSIZE;
  145.     saioPtr->si_ma = ioPtr->buffer;
  146.  
  147.     if (saioPtr->si_boottab->b_devinfo) {
  148.     maxlen = saioPtr->si_boottab->b_devinfo->d_maxiobytes;
  149.     } else {
  150.     maxlen = DEV_BSIZE;
  151.     }
  152.     /*
  153.      * Break the I/O in to chunks that are edible by the device.
  154.      */
  155.     totalBytes = 0;
  156.     len = ioPtr->length;
  157.     while (len > 0) {
  158.     if (len > maxlen) {
  159.         saioPtr->si_cc = maxlen;
  160.     } else {
  161.         saioPtr->si_cc = len;
  162.     }
  163.     numBytes = (*saioPtr->si_boottab->b_strategy)(saioPtr, READ);
  164.     if (numBytes <= 0) {
  165.         break;
  166.     }
  167.     saioPtr->si_ma += numBytes;
  168.     saioPtr->si_bn += numBytes / DEV_BSIZE;
  169.     len -= numBytes;
  170.     totalBytes += numBytes;
  171.     }
  172.     replyPtr->length = totalBytes;
  173.     if (numBytes < 0) {
  174.     return(FAILURE);
  175.     } else {
  176.     return(SUCCESS);
  177.     }
  178. }
  179.